package cc.mxtt.mvc.service.impl;

import com.jfinal.plugin.activerecord.Page;

import cc.mxtt.mvc.model.Device;
import cc.mxtt.mvc.model.Pile;
import cc.mxtt.mvc.model.Project;
import cc.mxtt.mvc.service.PileService;
import cc.mxtt.mvc.service.ProjectService;

public class PileServiceImpl implements PileService {

	@Override
	public Page<Pile> getDataGrid(int pageNumber, int pageSize, String username) {
		// id= name=ss address=ss jiandu=ss jiance=ss person=sss time=2016-03-11
		// jianshe=ss jianli sheji=ss kancha=ss jizhuang=ss weituo=ss
		String select = "select id,name,project,testLen,section,testDate";
		String formwhere = "from sys_pile where projectId != 0";
		formwhere = formwhere + " order by id asc";

		return Pile.dao.paginate(pageNumber, pageSize, select, formwhere);
	}

	@Override
	public Page<Pile> getDataGrid(int pageNumber, int pageSize,
			String username, Long id) {
		// id= name=ss address=ss jiandu=ss jiance=ss person=sss time=2016-03-11
		// jianshe=ss jianli sheji=ss kancha=ss jizhuang=ss weituo=ss
		String select = "select id,name,project,testLen,section,testDate";
		String formwhere = "from sys_pile where projectId != 0 and parent_id ="+id;
		formwhere = formwhere + " order by id asc";

		return Pile.dao.paginate(pageNumber, pageSize, select, formwhere);
	}

	@Override
	public Page<Pile> getSortDataGrid(int pageNumber, int pageSize,
			String username) {
		String select = "select id,name,project,testLen,section,testDate";
		String formwhere = "from sys_pile where projectId = 0";
		formwhere = formwhere + " order by id asc";

		return Pile.dao.paginate(pageNumber, pageSize, select, formwhere);
	}

	@Override
	public Page<Pile> getSortGrid(int pageNumber, int pageSize,
			String username, Long id) {
		String select = "select id,name,project,testLen,section,testDate";
		String formwhere = "from sys_pile where projectId = 0 and parent_id ="+id;
		formwhere = formwhere + " order by id asc";

		return Pile.dao.paginate(pageNumber, pageSize, select, formwhere);
	}

	@Override
	public Page<Pile> getProjectDataGrid(int pageNumber, int pageSize,
			String username) {
		String select = "select id,name,project,testLen,section,testDate";
		String formwhere = "from sys_pile order by projectId";
		return Pile.dao.paginate(pageNumber, pageSize, select, formwhere);
	}

	@Override
	public Page<Pile> getProjectDataGrid(int pageNumber, int pageSize,
			String username, Long id) {
		String select = "select id,name,project,testLen,section,testDate";
		String formwhere = "from sys_pile where parent_id ="+id;
		formwhere = formwhere + " order by projectId";

		return Pile.dao.paginate(pageNumber, pageSize, select, formwhere);
	}

}
